<template>
	<view class="home">
		<!-- 轮播 -->
		<swiper indicator-dots circular autoplay="true">
			<swiper-item v-for="swiperItem in swiper" :key="swiperItem.id">
				<image :src="swiperItem.image_src" mode="widthFix"></image>
			</swiper-item>			
		</swiper>
		<!-- 导航 -->
		<view class="nav">
			<navigator url="../goods/goods" class="nav_item">
				<view class="iconfont icon-ziyuan"></view>
				<text>商品超市</text>			
			</navigator>		
			<navigator url="../contact/contact" class="nav_item">
				<view class="iconfont icon-guanyuwomen"></view>
				<text>联系我们</text>
			</navigator>	
			<navigator class="nav_item">
				<view class="iconfont icon-tupian"></view>
				<text>社区图片</text>
			</navigator>
			<navigator class="nav_item">
				<view class="iconfont icon-shipin"></view>
					<text>学习视频</text>
			</navigator>			
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">
				推荐商品
			</view>
			<good-list :goods="goods"></good-list>
		</view>
	</view>
</template>

<script>
	import goodList from "../../components/goods-list.vue"
	export default {
		data() {
			return {
				swiper:[],
				goods:[],
				navs:[]
			}
		},
		components:{goodList},
		onLoad() {
			this.getSwiper();
			this.getHotGoods()
		},
		methods: {
			async getSwiper(){
				const res = await this.$myRequest({
					url:'/home/swiperdata'
				})	
				this.swiper = res.data.message;
			},	
			// 获取热门商品列表数据
			async getHotGoods(){
				const res=await this.$myRequest({
					url:"/goods/search?pagenum=1&pagesize=10"
				})				
				this.goods = res.data.message.goods;
				console.log(this.goods)
			}
		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 340rpx;
			image{
				width: 100%;
			}		
		}
		.nav{
			display: flex;
			padding: 10rpx 0 15rpx 0;
			.nav_item{
				flex: 1;
				text-align: center;
				text{
					font-size: 30rpx;
				}
				view{
					width: 120rpx;
					height: 120rpx;
					line-height: 120rpx;
					color: #FFFFFF;
					background-color: $shop-color;
					margin: 10rpx auto;
					overflow: hidden;
					border-radius: 50%;
					font-size: 50rpx;	
				}
				.icon-tupian{
					font-size: 45rpx;
				}
			}
		}
		.hot_goods{
			background-color: #eee;
			overflow: hidden;
			.tit{
				height: 50px;
				line-height: 50px;
				color: $shop-color;
				text-align: center;
				letter-spacing: 20px;
				background-color: #FFFFFF;
				margin: 10rpx 0;
			}			
		}
	}
</style>
